package com.anti.modular.sys.notice.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.sys.notice.param.SysNoticeParam;
import com.anti.modular.sys.notice.service.SysNoticeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统通知公告控制器
 *
 * @author xuyuxiang
 * @date 2020/6/28 17:18
 */
@RestController
@RequestMapping("sysNotice")
public class SysNoticeController {

    @Resource
    private SysNoticeService sysNoticeService;
    /**
     * 查询系统通知公告
     */
    @GetMapping("getNotices")
    @BusinessLog(title = "系统通知公告个人_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result getNotices() {
        return sysNoticeService.getNotices();
    }
    /**
     * 查询系统通知公告
     */
    @GetMapping("page")
    @BusinessLog(title = "系统通知公告_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysNoticeParam sysNoticeParam) {
        return Result.data(sysNoticeService.page(pageParam,sysNoticeParam));
    }

    /**
     * 查询我收到的系统通知公告
     */
    @GetMapping("received")
    @BusinessLog(title = "系统通知公告_已收", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result received(PageParam pageParam,SysNoticeParam sysNoticeParam) {
        return Result.data(sysNoticeService.received(pageParam,sysNoticeParam));
    }

    /**
     * 添加系统通知公告
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "系统通知公告_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysNoticeParam.add.class) SysNoticeParam sysNoticeParam) {
        sysNoticeService.add(sysNoticeParam);
        return Result.success("增加成功");
    }

    /**
     * 删除系统通知公告
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "系统通知公告_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysNoticeParam.delete.class) SysNoticeParam sysNoticeParam) {
        sysNoticeService.delete(sysNoticeParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑系统通知公告
     */
    @Permission
    @PostMapping("edit")
    @BusinessLog(title = "系统通知公告_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(SysNoticeParam.edit.class) SysNoticeParam sysNoticeParam) {
        sysNoticeService.edit(sysNoticeParam);
        return Result.success("编辑成功");
    }

    /**
     * 查看系统通知公告
     */
    @Permission
    @GetMapping("detail")
    @BusinessLog(title = "系统通知公告_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(SysNoticeParam.detail.class) SysNoticeParam sysNoticeParam) {
        return Result.data(sysNoticeService.detail(sysNoticeParam));
    }

    /**
     * 修改状态
     */
    @Permission
    @PostMapping("changeStatus")
    @BusinessLog(title = "系统通知公告_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public Result changeStatus(@RequestBody @Validated(SysNoticeParam.changeStatus.class) SysNoticeParam sysNoticeParam) {
        sysNoticeService.saveChangeStatus(sysNoticeParam);
        return Result.success("状态修改成功");
    }
}
